package day10;

import java.util.Random;

//a.有一个抽奖池,该抽奖池中存放了奖励的金额,该抽奖池用一个数组int[] arr = {10,5,20,50,100,200,500,800,2,80,300};
//创建两个抽奖箱(线程)设置线程名称分别为“抽奖箱1”，“抽奖箱2”，随机从arr数组中获取奖项元素并打印在控制台上,格式如下:
//抽奖箱1 又产生了一个 10 元大奖
//抽奖箱2 又产生了一个 100 元大奖
//.....
public class ChooseA {
    public static void main(String[] args) {
        int[] arr = {10, 5, 20, 50, 100, 200, 500, 800, 2, 80, 300};
        Random r = new Random();
        for (int i = 0; i < 2; i++) {
            new Thread(() -> {
                while (true) {
                    synchronized (ChooseA.class) {
                        try {
                            int n = r.nextInt(arr.length);
                            String name = Thread.currentThread().getName();
                            System.out.println(name + " 又产生了一个" + arr[n] + "元大奖!");
                            Thread.sleep(1000);
                            ChooseA.class.notifyAll();
                            ChooseA.class.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }, "抽奖箱" + (i + 1)).start();
        }
    }
}